<template>
  <view class="back-button" @click="goBack">
    <u-icon name="arrow-left" size="24" color="#333"></u-icon>
  </view>
</template>

<script setup>
function goBack() {
  // 获取当前页面路径
  const pages = getCurrentPages();
  const currentPage = pages[pages.length - 1];
  const currentPath = currentPage.route;
  
  // 如果是宠物详情页，返回到我的宠物页面
  if (currentPath === 'pages/pet/pet-detail') {
    uni.navigateBack({
      delta: 1,
      success: () => {
        console.log('返回成功');
      },
      fail: () => {
        // 如果返回失败，可能是没有上一页，直接跳转到我的宠物页面
        uni.navigateTo({
          url: '/pages/pet/my-pets'
        });
      }
    });
  } else {
    // 其他页面正常返回
    uni.navigateBack({
      delta: 1
    });
  }
}
</script>

<style lang="scss">
.back-button {
  position: fixed;
  top: 44px;
  left: 15px;
  width: 40px;
  height: 40px;
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}
</style>